package com.ruoyi.admin.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.IstOrder;
import com.ruoyi.admin.service.IIstOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 快定订单Controller
 * 
 * @author ruoyi
 * @date 2021-01-25
 */
@Controller
@RequestMapping("/istorder/order")
public class IstOrderController extends BaseController
{
    private String prefix = "istorder/order";

    @Autowired
    private IIstOrderService istOrderService;

    @RequiresPermissions("istorder:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询快定订单列表
     */
    @RequiresPermissions("istorder:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IstOrder istOrder)
    {
        startPage();
        List<IstOrder> list = istOrderService.selectIstOrderList(istOrder);
        return getDataTable(list);
    }

    /**
     * 导出快定订单列表
     */
    @RequiresPermissions("istorder:order:export")
    @Log(title = "快定订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IstOrder istOrder)
    {
        List<IstOrder> list = istOrderService.selectIstOrderList(istOrder);
        ExcelUtil<IstOrder> util = new ExcelUtil<IstOrder>(IstOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增快定订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快定订单
     */
    @RequiresPermissions("istorder:order:add")
    @Log(title = "快定订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IstOrder istOrder)
    {
        return toAjax(istOrderService.insertIstOrder(istOrder));
    }

    /**
     * 修改快定订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        IstOrder istOrder = istOrderService.selectIstOrderById(id);
        mmap.put("istOrder", istOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存快定订单
     */
    @RequiresPermissions("istorder:order:edit")
    @Log(title = "快定订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IstOrder istOrder)
    {
        return toAjax(istOrderService.updateIstOrder(istOrder));
    }

    /**
     * 删除快定订单
     */
    @RequiresPermissions("istorder:order:remove")
    @Log(title = "快定订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(istOrderService.deleteIstOrderByIds(ids));
    }
}
